package com.hskn.hss.module.casesetissuesource.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.casesetissuesource.entity.CasesetIssueSource;
import com.hskn.hss.module.casesetissuesource.mapper.CasesetIssueSourceMapper;
import com.hskn.hss.module.casesetissuesource.service.ICasesetIssueSourceService;
import com.hskn.hss.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Service
public class CasesetIssueSourceServiceImpl extends ServiceImpl<CasesetIssueSourceMapper, CasesetIssueSource> implements ICasesetIssueSourceService {

    @Resource
    private CasesetIssueSourceMapper casesetIssueSourceMapper;

    @Override
    public List<CasesetIssueSource> mList(JSONObject params) throws HssException {
        return list();
    }

    @Override
    public void mUpdate(JSONObject params) throws HssException {

        if (StringUtils.isEmpty(params) || StringUtils.isEmpty(params.getString("casesetIssueSourceId"))) {
            throw new HssException("参数错误");
        }
        CasesetIssueSource casesetIssueSource = JSON.parseObject(params.toJSONString(), CasesetIssueSource.class);
        casesetIssueSourceMapper.updateById(casesetIssueSource);
    }

    @Override
    public void add(JSONObject params) throws HssException {

        CasesetIssueSource casesetIssueSource = JSON.parseObject(params.toJSONString(), CasesetIssueSource.class);
        casesetIssueSourceMapper.insert(casesetIssueSource);
    }

    @Override
    public void del(JSONObject params) throws HssException {

        if (StringUtils.isEmpty(params) || StringUtils.isEmpty(params.getString("casesetIssueSourceId"))) {
            throw new HssException("参数错误");
        }
        String id = params.getString("casesetIssueSourceId");
        casesetIssueSourceMapper.deleteById(id);
    }
}
